package com.hxkcloud.patient.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.beans.ScaleInfoBean;

import java.util.List;

/**
 * Created by ray_lei on 2016/7/6.
 */
public class ScaleQuestionAdapter extends RecyclerView.Adapter<ViewHolder>{


    private Context mContext;
    private List<ScaleInfoBean> datas;
    private RecyclerView recyclerview;
    private LayoutInflater mInflater;

    private ResultSelectedListener listener;

    public ScaleQuestionAdapter(Context mContext, List<ScaleInfoBean> datas,
                                RecyclerView recyclerview, ResultSelectedListener listener) {
        this.mContext = mContext;
        this.datas = datas;
        this.recyclerview = recyclerview;
        this.listener = listener;
        mInflater = LayoutInflater.from(mContext);
    }

    public void setData(List<ScaleInfoBean> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    public void clearData() {
        datas.clear();
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        // TODO Auto-generated method stub
        return datas.size();
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        // TODO Auto-generated method stub


        Holder mHolder = (Holder) holder;

        mHolder.textTV.setText(datas.get(position).getTitle());

        mHolder.textTV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onSelected("item",datas.get(position));
            }
        });

//        mHolder.ageTV.setText("");
//        mHolder.sexTV.setText("");
//        mHolder.statusTV.setText("");
//        mHolder.iconCI.setImageResource();
//        mHolder.descrptionTV.setText("");
//        mHolder.layout.setOnClickListener(new View.OnClickListener(){
//
//            @Override
//            public void onClick(View v) {
//                listener.onSelected(datas.get(position));
//
//            }
//
//        });



    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {


        View v = mInflater.inflate(R.layout.item_scalequestion_layout, null);
        ViewHolder holer = new Holder(v);

        return holer;
    }

    @Override
    public int getItemViewType(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    /*
     * Holder
     */
    public class Holder extends ViewHolder {

        private TextView textTV;

        public Holder(View view) {
            super(view);
            textTV = (TextView) view.findViewById(R.id.scalequestion_item_tv_text);


        }
    }

    public interface ResultSelectedListener {
        void onSelected(String type, ScaleInfoBean info);
    }




}
